<?php

require_once  'common.php';

//if not logued in => go to login
$gc_token = $user->getSessionToken($fb_user_id);

if(isset($_GET['token'] )){
	$token = $_GET['token'];
}else{
	$token = null;
}



//si no esta en la base de datos, y esta el token en la url, se guarda en la base de datos
if( $gc_token == null && $token != null ){
	
  //genera el token de session
  $gc_token = Zend_Gdata_AuthSub::getAuthSubSessionToken($token);
  
	
  //aca hay que guardar en la base de datos el token
  $user->registerGoogleCalendarAccount( $fb_user_id, $gc_token );
  
  
}
//si no tengo el token en la url ni en la base de datos, hay que pedirlo.-->ir a login.php
else if( $gc_token == null && $token == null){
	header('Location: http://gosocial.com.ar/bundundu/login.php');
	exit;
}



?>

<fb:header>Welcome to Bundundu</fb:header>



<fb:tabs>
<fb:tab-item href='http://apps.facebook.com/bundundu/index.php?tab=1' title='Home' <?php echo((!isset($_GET['tab']) | (isset($_GET['tab']) & $_GET['tab']==1))? 'selected="true"':''); ?>/>
<fb:tab-item href='http://apps.facebook.com/bundundu/index.php?tab=2' title='New Event' <?php echo ((isset($_GET['tab']) & $_GET['tab']==2)? 'selected="true"':''); ?>/>
<fb:tab-item href='http://apps.facebook.com/bundundu/index.php?tab=4' title='My Calendars' <?php echo ((isset($_GET['tab']) & $_GET['tab']==4)? 'selected="true"':''); ?>/>
<fb:tab-item href='http://apps.facebook.com/bundundu/index.php?tab=3' title='Invite Friends' <?php echo ((isset($_GET['tab']) & $_GET['tab']==3)? 'selected="true"':''); ?>/>
<fb:tab-item href='http://apps.facebook.com/bundundu/index.php?tab=5' title='Prueba Eventos' <?php echo ((isset($_GET['tab']) & $_GET['tab']==5)? 'selected="true"':''); ?>/>
</fb:tabs>

<?php
		switch($_GET['tab'])
		{

			case 1:
				
				require_once( 'home.php' );
				break;
			case 2:
				require_once( 'newevent.php' );
				break;
			case 3:
				require_once( 'invite.php' );
				break;
			case 4:
				require_once( 'mycalendars.php' );
				break;
			case 5:
				require_once( 'events.php' );
				break;
			default:
				require_once( 'home.php' );
				break;
		}
?>

